//
//  MovieListView.swift
//  SwiftUi
//
//  Created by xm on 05/09/2025.
//

import SwiftUI

struct MoviesListView: View {
    let viewModel: MoviesViewModel
    init(viewModel: MoviesViewModel) {
        self.viewModel = viewModel
    }
    
    var body: some View {
        
        List {
            ForEach(viewModel.movies, id:\.id){ item in
                
                Text("电影 \(item.name)")
                    .frame(maxWidth: .infinity, maxHeight: .infinity,alignment: .leading)
//                .contentShape(Rectangle()) // 确保整个区域可点击
//                .listRowInsets(EdgeInsets())

                .background(Color.cyan)
                .onTapGesture {
                    print("xxxx")
                    viewModel.didSelect(movie: item)
                }
            }
        }.task {
            print("task")
            await viewModel.fetch()
        }
    
    }
}

#Preview {
    let coordinator = MoviesCoordinator()
    let viewModel = MoviesViewModel( coordinator: coordinator)
    MoviesListView(viewModel: viewModel)
}
